home *** CD-ROM | disk | FTP | other *** search
/ 3D World 123 / 3DW_123.iso / pc / 3dw.exe / 3dw.dxr / Internal_18_Fade In Out.ls < prev    next >
Encoding:
Text File  |  2009-06-30  |  4.6 KB  |  156 lines

  1. property pSprite, pStart, pActive, pCompleteCycles, pFadeDiff, pFaded, pAuto, pFadeMax, pFadeMin, pCycles, pPeriodBase, pPeriod
  2.  
  3. on getBehaviorDescription me
  4.   return "FADE IN/OUT" & RETURN & RETURN & "Gives the appearance of a sprite fading in or out. " & "Choose whether the sprite should first appear at maximum (faded in) or minimum (faded out) values, when the fading should start, the minimum and maximum fade values, the number of times it should fade, and how fast it should fade. " & "The fade can be activated automatically in the first frame, by a click on the sprite, or by sending the sprite an mFadeActivate message." & RETURN & RETURN & "PERMITTED MEMBER TYPES:" & RETURN & "animated GIF, bitmap, Flash, text, vector shape" & RETURN & RETURN & "PARAMETERS:" & RETURN & "* Fade in or out?" & RETURN & "* Maximum fade value" & RETURN & "* Minimum fade value" & RETURN & "* Fade activation (automatic, click, or message)" & RETURN & "* Number of fade cycles" & RETURN & "* Time period for fade in seconds" & RETURN & RETURN & "Set the number of fade cycles to -1 if you want an endless loop, or to 0 if the fade should happen only once."
  5. end
  6.  
  7. on getBehaviorTooltip me
  8.   return "Fades a sprite between two fade values once, multiple times, or indefinitely. " & "The fade can be initiated automatically, by mouse click, or via a message to the sprite."
  9. end
  10.  
  11. on beginSprite me
  12.   pFaded = resolve(pFaded)
  13.   pAuto = resolve(pAuto)
  14.   mInitialize(me)
  15. end
  16.  
  17. on resolve prop
  18.   case prop of
  19.     pFaded:
  20.       choiceslist = ["In", "Out"]
  21.       lookup = [#in, #out]
  22.     pAuto:
  23.       choiceslist = ["Automatic", "Click", "Message"]
  24.       lookup = [#automatic, #click, #message]
  25.   end case
  26.   return lookup[findPos(choiceslist, prop)]
  27. end
  28.  
  29. on prepareFrame me
  30.   mUpdate(me)
  31. end
  32.  
  33. on mouseUp me
  34.   if pAuto = #click then
  35.     mActivate(me)
  36.   end if
  37. end
  38.  
  39. on mInitialize me
  40.   pSprite = sprite(me.spriteNum)
  41.   pActive = #off
  42.   pCompleteCycles = 0.5
  43.   pPeriod = pPeriodBase * 1000
  44.   if pFadeMax < pFadeMin then
  45.     vMax = pFadeMax
  46.     pFadeMax = pFadeMin
  47.     pFadeMin = vMax
  48.   end if
  49.   pFadeDiff = pFadeMax - pFadeMin
  50.   if pFaded = #in then
  51.     pSprite.blend = pFadeMin
  52.   else
  53.     pSprite.blend = pFadeMax
  54.   end if
  55.   if pAuto = #automatic then
  56.     mActivate(me)
  57.   end if
  58. end
  59.  
  60. on mUpdate me
  61.   if pActive <> #off then
  62.     vMillis = the milliSeconds
  63.     vElapsed = vMillis - pStart
  64.     if vElapsed >= pPeriod then
  65.       case pActive of
  66.         #in:
  67.           pSprite.blend = pFadeMax
  68.         #out:
  69.           pSprite.blend = pFadeMin
  70.       end case
  71.       pActive = #off
  72.       mCheckCycle(me)
  73.     else
  74.       vFadeDiff = integer(pFadeDiff * vElapsed / pPeriod)
  75.       case pActive of
  76.         #in:
  77.           pSprite.blend = pFadeMin + vFadeDiff
  78.         #out:
  79.           pSprite.blend = pFadeMax - vFadeDiff
  80.       end case
  81.     end if
  82.   end if
  83. end
  84.  
  85. on mActivate me
  86.   if pFadeDiff then
  87.     case pFaded of
  88.       #in:
  89.         mFadeIn(me)
  90.       #out:
  91.         mFadeOut(me)
  92.     end case
  93.   end if
  94. end
  95.  
  96. on mCheckCycle me
  97.   vContinue = 0
  98.   case pCycles of
  99.     (-1):
  100.       vContinue = 1
  101.     0:
  102.       vContinue = 0
  103.     otherwise:
  104.       pCompleteCycles = pCompleteCycles + 0.5
  105.       if integer(pCompleteCycles) <= pCycles then
  106.         vContinue = 1
  107.       end if
  108.   end case
  109.   if vContinue then
  110.     if pSprite.blend = pFadeMax then
  111.       mFadeOut(me)
  112.     else
  113.       mFadeIn(me)
  114.     end if
  115.   end if
  116. end
  117.  
  118. on mFadeIn me
  119.   mFade(me, #in)
  120. end
  121.  
  122. on mFadeOut me, vTarget
  123.   mFade(me, #out)
  124. end
  125.  
  126. on mFade me, vInOut
  127.   pActive = vInOut
  128.   pStart = the milliSeconds
  129. end
  130.  
  131. on mFadeActivate me
  132.   if pAuto = #message then
  133.     mActivate(me)
  134.   end if
  135. end
  136.  
  137. on isOKToAttach me, aSpriteType, aSpriteNum
  138.   case aSpriteType of
  139.     #graphic:
  140.       return getPos([#animGif, #bitmap, #flash, #text, #vectorShape], sprite(aSpriteNum).member.type) <> 0
  141.     #script:
  142.       return 0
  143.   end case
  144. end
  145.  
  146. on getPropertyDescriptionList me
  147.   vPDList = [:]
  148.   setaProp(vPDList, #pFaded, [#comment: "Fade in or out?", #format: #string, #default: "In", #range: ["In", "Out"]])
  149.   setaProp(vPDList, #pFadeMax, [#comment: "Maximum Fade Value", #format: #integer, #default: 100, #range: [#min: 0, #max: 100]])
  150.   setaProp(vPDList, #pFadeMin, [#comment: "Minimum Fade Value", #format: #integer, #default: 0, #range: [#min: 0, #max: 100]])
  151.   setaProp(vPDList, #pAuto, [#comment: "Start automatically, when clicked, or by message?", #format: #string, #default: "Automatic", #range: ["Automatic", "Click", "Message"]])
  152.   setaProp(vPDList, #pCycles, [#comment: "Fade cycles (0 = one fade only, -1 = repeat forever)", #format: #integer, #default: 0, #range: [#min: -1, #max: 10]])
  153.   setaProp(vPDList, #pPeriodBase, [#comment: "Time period for fade (seconds)", #format: #float, #default: 2.0, #range: [#min: 0.25, #max: 15.0]])
  154.   return vPDList
  155. end
  156.